package com.songyuquan.webcs.controller;

import com.alipay.api.AlipayApiException;
import com.songyuquan.webcs.pojo.AlipayBean;
import com.songyuquan.webcs.service.PayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

/***
 * 调用支付宝的接口
 */
@RestController
public class PayController {
    @Autowired
    private PayService payService;

    /**
     * 支付宝支付 api
     */
    @PostMapping(value = "/order/alipay")
    public String alipay(String outTradeNo, String subject, String totalAmount, String description) throws AlipayApiException {
        AlipayBean order = new AlipayBean();
        order.setOut_trade_no(outTradeNo);
        order.setSubject(subject);
        order.setTotal_amount(totalAmount);
        order.setDescription(description);
        System.out.println(order);
        String result = payService.aliPay(order);
        System.out.println("result" + result);
        return result;
    }
}
